grammar BPSL;

options{
	language=Java;
	output=AST;
	ASTLabelType=CommonTree;
}

tokens{
	DISJUNCTION = '^';
	ROOT;
	VARDEF;
	FORMULA;
	CLASSDEF;
	TYPEDVARDEF;
	METHODDEF;
}

@header{
	package modelbuilding.analysis.bpsl;
}
@lexer::header{
	package modelbuilding.analysis.bpsl;
}


//syntactic specification

specification	:	PATTERNNAME ':='! formula
			;

formula		:      '\\exist'! vardef predicateSection 
			;

vardef		:	ID (',' ID )* '\\element' type ';' -> ^(type ID+)
			|	ID (',' ID )* '\\element' type ';' vardef -> ^(type ID+) vardef
			;

type			:	'\\C'
				-> CLASSDEF
			|	'\\V'
				-> TYPEDVARDEF
			|	'\\M'
				-> METHODDEF
			;

predicateSection	:	atom | atom DISJUNCTION! predicateSection
			;
		
atom			:	PREDICATE '(' term ',' term ')'
				-> ^(PREDICATE term term)
			;
	
term			:	ID
			;
		

//lexical specification

PREDICATE		:     'Defined-in'
			|	'Reference-to-one'
			|	'Reference-to-many'
			|	'Inheritance'
			|	'Creation'
			|	'Invocation'
			|	'Argument'
			|	'Return-type'
			;

PATTERNNAME		: 	'\\'( 'a'..'z' | 'A'..'Z' ) ( 'a'..'z' | 'A'..'Z' | '0'..'9' | '-' |'_' )*
			;

ID			:	( 'a'..'z'	| 'A'..'Z' ) ( 'a'..'z' | 'A'..'Z' | '0'..'9' | '-' |'_' )*
			;

//whitespace, tabulator and newline are matched to token WS and not feeded to the parser
WS  			:  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
    			;
